﻿using Map;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Trie
{
    class Program
    {
        static void Main(string[] args)
        {

            //C# 字典字典树   System.Collections.Generic.Dictionary<object, object> dic = new System.Collections.Generic.Dictionary<object, object>();



            Console.WriteLine("Pride and Prejudice");
            List<string> words = new FileOperation(Directory.GetCurrentDirectory() + @"\Txt\pride-and-prejudice.txt").readFile();



            Console.WriteLine("Total words: " + words.Count);

            Stopwatch timer = new Stopwatch();
            timer.Start();


            BSTMap<string, int> batmap = new BSTMap<string, int>();
            foreach (var word in words)
            {
                if (batmap.contains(word))
                    batmap.set(word, batmap.get(word) + 1);
                else
                    batmap.add(word, 1);
            }

            timer.Stop();

            Console.WriteLine("Total different words: " + batmap.getSize());
            Console.WriteLine("BSTSet: " + timer.Elapsed.TotalSeconds + " s"); ;

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            timer = new Stopwatch();
            timer.Start();

            Trie trie = new Trie();
            foreach (var word in words)
                trie.add(word);

            foreach (var word in words)
                trie.contains(word);

            timer.Stop();

            Console.WriteLine("Total different words: " + trie.getSize());
            Console.WriteLine("Trie: " + timer.Elapsed.TotalSeconds + " s"); ;

        }
    }
}
